﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.BackgroundWorkers;
using Volo.Abp.Threading;

namespace Himp.TaskScheduling
{
    public class RedisConvertMqttWorker : AsyncPeriodicBackgroundWorkerBase
    {
        public RedisConvertMqttWorker(
                        AbpAsyncTimer timer,
                        IServiceScopeFactory serviceScopeFactory
                    ) : base(
                        timer,
                        serviceScopeFactory)
        {
            Timer.Period = 6000; //10 minutes
        }

        protected async override Task DoWorkAsync(
            PeriodicBackgroundWorkerContext workerContext)
        {
            Logger.LogInformation("Starting: Setting status of inactive users...");


            var a = await RedisHelper.GetString("bb");
            Logger.LogInformation($"{a}");
            await MqttClientHelper.PublishStringAsync("aa/aa", a);

            Logger.LogInformation("Completed: Setting status of inactive users...");
        }
    }
}
